package com.dragon.mmochat.service;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.transaction.annotation.Transactional;

import com.dragon.mmochat.MmochatConstant;
import com.dragon.mmochat.MmochatMain;
import com.dragon.mmochat.model.MmochatActivityRecord;
import com.dragon.mmochat.model.MmochatEventLog;
import com.dragon.mmochat.model.MmochatRolePayInfo;
import com.dragon.mmochat.model.deal.MmochatBigMoneyDeal;
import com.dragon.mmochat.model.deal.MmochatDealLog;
import com.dragon.mmochat.model.enumType.MmochatActivityRecordType;
import com.dragon.mmochat.model.enumType.MmochatBigMoneyDealType;
import com.dragon.mmochat.model.enumType.MmochatGangMemberType;
import com.dragon.mmochat.model.enumType.MmochatPkTeamMemberType;
import com.dragon.mmochat.model.enumType.MmochatSecondRoleType;
import com.dragon.mmochat.model.enumType.MmochatServerType;
import com.dragon.mmochat.model.gang.MmochatGang;
import com.dragon.mmochat.model.gang.MmochatGangMember;
import com.dragon.mmochat.model.kefu.MmochatKefuOptionLog;
import com.dragon.mmochat.model.mergeServer.MergeStep1Model1;
import com.dragon.mmochat.model.mergeServer.MergeStep1Model4;
import com.dragon.mmochat.model.mergeServer.MergeStep2Model1;
import com.dragon.mmochat.model.pkteam.MmochatPkTeam;
import com.dragon.mmochat.model.pkteam.MmochatPkTeamMember;
import com.dragon.mmochat.model.role.MmochatGm;
import com.dragon.mmochat.model.role.MmochatPlayer;
import com.dragon.mmochat.model.role.MmochatRankPlayer;
import com.dragon.mmochat.model.role.MmochatSimplePlayer;
import com.dragon.mmochat.model.shop.MmochatPlayerShop;
import com.dragon.mmochat.model.statistics.MmochatBigMoneyStatistics;
import com.dragon.mmochat.model.statistics.MmochatDailyMoneyStatistics;
import com.dragon.mmochat.model.statistics.MmochatDailyUserStatistics;
import com.dragon.mmochat.model.statistics.MmochatMonthlyStatistics;
import com.dragon.mmochat.model.statistics.MmochatRoleLevelInfo;
import com.dragon.mmochat.model.statistics.MmochatRoleLevelInfoStatistics;
import com.dragon.mmochat.model.statistics.MmochatSmallMoneyStatistics;
import com.dragon.mmochat.model.task.MmochatTask;
import com.dragon.mmochat.util.MmochatUtil;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

/*
 * 增加这个类的主要目的是为了将[类转化为Gson字符串的过程]放到数据库原子操作之外,
 * 同时又使调用方不必太过繁琐得将每个Gson字符串传参进来
 */
public class MmochatDao {

	// 获取skyId的角色列表
	public static List<MmochatSimplePlayer> getRoleList(long skyId) {
		if (!MmochatMain.serverType.isHasDao()) {
			return new ArrayList<MmochatSimplePlayer>();
		}
		return MmochatMain.getDaoService().getRoleList(skyId);
	}

	// 获取skyId的所有角色列表
	public static List<MmochatSimplePlayer> getAllRoleList(long skyId) {
		if (!MmochatMain.serverType.isHasDao()) {
			return new ArrayList<MmochatSimplePlayer>();
		}
		return MmochatMain.getDaoService().getAllRoleList(skyId);
	}

	// 创建新角色ID
	public static int createNewRoleId() {
		return MmochatMain.getDaoService().createNewRoleId();
	}

	// 增加新的角色
	public static void createRole(long skyId, String name, int sexual,
			int family, int roleTypeValue, int friendListBmp,
			String suggest_name, String imei) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().createRole(skyId, name, sexual, family,
				roleTypeValue, friendListBmp, suggest_name, imei);
	}

	// 增加新的角色
	public static void createRole2(int roleId, long skyId, String name,
			int sexual, int family, int roleTypeValue, int friendListBmp,
			String suggest_name, String imei, long createTime, int smallMoney,
			int bigMoney, int level) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().createRole2(roleId, skyId, name, sexual,
				family, roleTypeValue, friendListBmp, suggest_name, imei,
				createTime, smallMoney, bigMoney, level);
	}

	// 删除角色
	public static void delRole(int id, boolean delete) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().delRole(id, delete);
	}

	// 获取roleId的角色
	public static MmochatPlayer getRole(int roleId) {
		if (!MmochatMain.serverType.isHasDao()) {
			return null;
		}
		return MmochatMain.getDaoService().getRole(roleId);
	}

	// 获取roleId的角色
	public static MmochatPlayer getRoleIncludeDeleted(int roleId) {
		if (!MmochatMain.serverType.isHasDao()) {
			return null;
		}
		return MmochatMain.getDaoService().getRoleIncludeDeleted(roleId);
	}

	// 更新角色第一次登陆游戏
	public static void updateRoleFirstEnterGame(MmochatPlayer me) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		String myPackage = me.getGson_myPackage();
		String myStorage = me.getGson_myStorage();
		String tasks = me.getGson_tasks();
		int login_time = me.getLogin_time();
		int roleId = me.getRoleId();
		MmochatMain.getDaoService().updateRoleFirstEnterGame(myPackage,
				myStorage, tasks, login_time, roleId);
	}

	// 更新角色切换地图
	public static void updateRoleEnterNewMap(MmochatPlayer me) {
		// if (me != null) {
		// MmochatMain.getDaoService().updateRoleEnterNewMap(me.getCurBlood(),
		// me.getCurSprit(), me.getGson_pets(),
		// me.getGson_propEffects(), me.getMapId(), me.getX(),
		// me.getY(), me.getGson_myFans(), me.getGson_myIdols(),
		// me.isAcceptStrangerMessage(), me.isCheckAddMeFriend(),
		// me.isAcceptAddMeFriend(), me.getGson_myPackage(),
		// me.getGson_tasks(), me.getLatest_login_time(),
		// me.getRoleId());
		// }
	}

	// 更新角色离开游戏
	public static void updateRoleLeaveGame(MmochatPlayer me) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		if (me != null) {
			List<MmochatPlayer> args = new ArrayList<MmochatPlayer>();
			args.add(me);
			batchUpdateRoleLeaveGame(args);
		}
	}

	// 批量更新角色离开游戏
	public static void batchUpdateRoleLeaveGame(
			Collection<MmochatPlayer> players) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		if (players == null || players.size() == 0) {
			return;
		}
		List<Object[]> args = new ArrayList<Object[]>();
		for (MmochatPlayer me : players) {
			if (me != null) {
				try {
					args.add(new Object[] { me.getCurBlood(), me.getCurSprit(),
							me.getGson_pets(), me.getGson_propEffects(),
							me.getMapId(), me.getLine(), me.getX(), me.getY(),
							me.getGson_myFans(), me.getGson_myIdols(),
							me.isAcceptStrangerMessage(),
							me.isCheckAddMeFriend(), me.isAcceptAddMeFriend(),
							me.getGson_myPackage(), me.getGson_tasks(),
							System.currentTimeMillis(),
							me.getLatest_login_time(), me.getLevel(),
							me.getExp(), me.getDao(), me.getZhanji(),
							me.getBlood_point(), me.getAttack_point(),
							me.getSprit_point(), me.getSpeed_point(),
							me.getSpace_point(), me.getSmall_money(),
							me.getBig_money(), me.getTeacherScore(),
							me.getAttack_gift_point(),
							me.getSprit_gift_point(), me.getBlood_gift_point(),
							me.getDefend_gift_point(),
							me.getSpeed_gift_point(), me.getSpace_gift_point(),
							me.getCur_month_login_day_num(),
							me.getGson_friends(), me.getName(),
							me.getGson_dailyActivities(), me.getFuBenId(),
							me.getGson_specialSkills(), me.getPk_score(),
							me.getGson_lifeSkills(), me.getRoleId() });
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
		if (args.size() == 0) {
			return;
		}
		MmochatMain.getDaoService().batchUpdateRoleLeaveGame(args);
	}

	// 更新任务列表
	public static void updateRoleTasks(MmochatPlayer me) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		if (me != null) {
			MmochatMain.getDaoService().updateRoleTasks(me.getGson_tasks(),
					me.getRoleId());
		}
	}

	// 玩家交易
	public static void makeDeal(MmochatPlayer me, int myDealSmallMoney,
			String myImei, String myDealPackLog, MmochatPlayer he,
			int hisDealSmallMoney, String hisImei, String hisDealPackLog) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		if (me == null || he == null) {
			return;
		}
		// 交易的钱
		int myAddSmallMoney = 0, hisAddSmallMoney = 0;
		if (myDealSmallMoney > 0) {
			myAddSmallMoney += -1 * myDealSmallMoney;
			hisAddSmallMoney += myDealSmallMoney;
		}
		if (hisDealSmallMoney > 0) {
			hisAddSmallMoney += -1 * hisDealSmallMoney;
			myAddSmallMoney += hisDealSmallMoney;
		}
		List<Object[]> args = new ArrayList<Object[]>();
		args.add(new Object[] { myAddSmallMoney, me.getGson_myPackage(),
				me.getGson_pets(), me.getRoleId() });
		args.add(new Object[] { hisAddSmallMoney, he.getGson_myPackage(),
				he.getGson_pets(), he.getRoleId() });

		MmochatMain.getDaoService().makeDeal(me, myAddSmallMoney, myImei,
				myDealPackLog, he, hisAddSmallMoney, hisImei, hisDealPackLog,
				args);
	}

	// 更新技能列表
	public static void updateRoleSkills(MmochatPlayer me, int needSmallMoney) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		if (me != null) {
			MmochatMain.getDaoService().updateRoleSkills(me.getGson_skills(),
					needSmallMoney, me.getRoleId());
		}
	}

	// 更新角色换线
	public static void updateRoleChangeLine(MmochatPlayer me, int line) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().updateRoleChangeLine(line, me.getRoleId());
	}

	// 更新宠物列表
	public static void updateRolePets(MmochatPlayer me) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		if (me != null) {
			MmochatMain.getDaoService().updateRolePets(me.getGson_pets(),
					me.getRoleId());
		}
	}

	// 更新临时任务序列号
	public static void decreaseTempTaskSerial(int delta) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().decreaseTempTaskSerial(delta);
	}

	// 更新临时任务序列号
	public static void decreaseBossSerial(int delta) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().decreaseBossSerial(delta);
	}

	// 更新所有序列号
	public static void updateSerial(int bossId, int taskId) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().updateSerial(bossId, taskId);
	}

	// 更新任务数据
	public static void updateRoleFinishTask(MmochatPlayer me) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		if (me == null) {
			return;
		}
		MmochatMain.getDaoService().updateRoleAfterTask(me.getLevel(),
				me.getExp(), me.getDao(), me.getZhanji(), me.getCurBlood(),
				me.getCurSprit(), me.getBlood_point(), me.getAttack_point(),
				me.getSprit_point(), me.getSpeed_point(), me.getSpace_point(),
				(int) me.getSmall_money(), me.getGson_pets(),
				me.getGson_tasks(), me.getGson_propEffects(),
				(int) me.getBig_money(), me.getTeacherScore(),
				me.getGson_myPackage(), me.getAttack_gift_point(),
				me.getSprit_gift_point(), me.getBlood_gift_point(),
				me.getDefend_gift_point(), me.getSpeed_gift_point(),
				me.getSpace_gift_point(), me.getRoleId());
	}

	// 更新打怪数据
	// 系统每隔400ms可以处理一次此项操作
	public static void batchUpdateSqlAfterBattle(MmochatPlayer me) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		if (me == null) {
			return;
		}
		List<Object[]> args = new ArrayList<Object[]>();
		try {
			args.add(new Object[] { me.getLevel(), me.getExp(), me.getDao(),
					me.getZhanji(), me.getCurBlood(), me.getCurSprit(),
					me.getBlood_point(), me.getAttack_point(),
					me.getSprit_point(), me.getSpeed_point(),
					me.getSpace_point(), me.getSmall_money(),
					me.getGson_pets(), me.getBig_money(), me.getTeacherScore(),
					me.getGson_myPackage(), me.getAttack_gift_point(),
					me.getSprit_gift_point(), me.getBlood_gift_point(),
					me.getDefend_gift_point(), me.getSpeed_gift_point(),
					me.getSpace_gift_point(), me.getGson_friends(),
					me.getRoleId() });
		} catch (Exception e) {
			e.printStackTrace();
		}
		MmochatMain.getDaoService().batchUpdateSqlAfterBattle(args);
	}

	// 角色加点:属性点，空白属性点
	public static void updateRolePoint(MmochatPlayer me) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().updateRolePoint(me);
	}

	// 角色加天赋:天赋点，空白天赋点
	public static void updateRoleGiftPoint(MmochatPlayer me) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().updateRoleGiftPoint(me);
	}

	// 吃药品后更新：更新药品集合,人当前气血，法力
	public static void updateRoleAfterEatDrug(MmochatPlayer me) {
		// MmochatMain.getDaoService().updateRoleAfterEatDrug(
		// me.getGson_myPackage(), me.getCurBlood(), me.getCurSprit(),
		// me.getGson_pets(), me.getRoleId());
	}

	// 更新好友列表
	public static void updateMyFriends(MmochatPlayer me) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().updateMyFriends(me.getGson_friends(),
				me.getRoleId());
	}

	// 更新黑名单列表
	public static void updateMyEnermys(MmochatPlayer me) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().updateMyEnermys(me.getGson_enermys(),
				me.getGson_friends(), me.getRoleId());
	}

	// 同时更新好友和黑名单
	public static void updateMyFriendsAndEnermys(MmochatPlayer me) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().updateMyFriendsAndEnermys(
				me.getGson_enermys(), me.getGson_friends(), me.getRoleId());
	}

	// 购买药品
	public static void buyDrug(MmochatPlayer me, int moneyNeed) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().buyDrug(me.getGson_myPackage(), moneyNeed,
				me.getRoleId());
	}

	// 购买物品
	public static void buySmallMoneyObj(MmochatPlayer me, int moneyNeed) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().buySmallMoneyObj(me.getGson_myPackage(),
				moneyNeed, me.getRoleId());
	}

	// 购买物品
	public static void buyBigMoneyObj(MmochatPlayer me, int moneyNeed) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().buyBigMoneyObj(me.getGson_myPackage(),
				moneyNeed, me.getLimit_bigmoney(), me.getRoleId());
	}

	// 出售装备
	public static void sellEquip(MmochatPlayer me, int moneyAward) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().sellEquip(me.getGson_myPackage(),
				moneyAward, me.getRoleId());
	}

	// 更新钱庄游戏币
	public static void updateStoreMoney(MmochatPlayer me) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().updateStoreMoney(me.getStoredSmall_money(),
				(int) me.getSmall_money(), me.getRoleId());
	}

	// 更新钱庄宠物
	public static void updateStorePet(MmochatPlayer me) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().updateStorePet(me.getGson_stored_pets(),
				me.getRoleId());
	}

	// 获取前30名等级排行
	public static List<MmochatRankPlayer> getTopLevelList() {
		if (!MmochatMain.serverType.isHasDao()) {
			return new ArrayList<MmochatRankPlayer>();
		}
		return MmochatMain.getDaoService().getTopLevelList();
	}

	// 获取前30名道行排行
	public static List<MmochatRankPlayer> getTopDaoList() {
		if (!MmochatMain.serverType.isHasDao()) {
			return new ArrayList<MmochatRankPlayer>();
		}
		return MmochatMain.getDaoService().getTopDaoList();
	}

	// 获取前20名道行排行，一定等级内
	public static List<MmochatRankPlayer> getTopDaoListByLevel(int minLevel,
			int maxLevel) {
		if (!MmochatMain.serverType.isHasDao()) {
			return new ArrayList<MmochatRankPlayer>();
		}
		return MmochatMain.getDaoService().getTopDaoListByLevel(minLevel,
				maxLevel);
	}

	// 获取前30名战绩排行
	public static List<MmochatRankPlayer> getTopZhanjiList() {
		if (!MmochatMain.serverType.isHasDao()) {
			return new ArrayList<MmochatRankPlayer>();
		}
		return MmochatMain.getDaoService().getTopZhanjiList();
	}

	// 获取前30名金钱排行
	public static List<MmochatRankPlayer> getTopSmallMoneyList() {
		if (!MmochatMain.serverType.isHasDao()) {
			return new ArrayList<MmochatRankPlayer>();
		}
		return MmochatMain.getDaoService().getTopSmallMoneyList();
	}

	// 更新每日领药活动
	public static void updateFreeDrugActivity(MmochatPlayer me) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().updateFreeDrugActivity(
				me.getGson_myPackage(), me.getGson_dailyActivities(),
				me.getRoleId());
	}

	// 更新道具效果
	public static void updateRoleAfterUseProp(MmochatPlayer me) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().updateRoleAfterUseProp(me.getName(),
				me.getLevel(), me.getExp(), me.getMapId(), me.getX(),
				me.getY(), me.getCurBlood(), me.getCurSprit(),
				me.getBlood_point(), me.getAttack_point(), me.getSprit_point(),
				me.getSpeed_point(), (int) me.getSmall_money(),
				(int) me.getBig_money(), me.getSpace_point(), me.getDao(),
				me.getZhanji(), me.getGson_myPackage(), me.getGson_pets(),
				me.getGson_propEffects(), me.getAttack_gift_point(),
				me.getSprit_gift_point(), me.getBlood_gift_point(),
				me.getDefend_gift_point(), me.getSpeed_gift_point(),
				me.getSpace_gift_point(), me.getGson_dailyActivities(),
				me.getGson_specialSkills(), me.getGson_lifeSkills(),
				me.getRoleId());
	}

	// 改名
	public static void updateRoleName(MmochatPlayer me, String newName) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().updateRoleName(newName,
				me.getGson_myPackage(), me.getRoleId());
	}

	// 改造装备
	public static void modifyEquip(MmochatPlayer me, int smallMoneyNeed) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().modifyEquip(me.getGson_myPackage(),
				smallMoneyNeed, me.getRoleId());
	}

	// 更新玩家显示设置
	public static void updateRoleShowSet(MmochatPlayer me) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().updateRoleShowSet(
				me.getShowRoleSet().getValue(), me.getRoleId());
	}

	// 更新聊天频道设置
	public static void updateRoleChatSet(MmochatPlayer me) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().updateRoleChatSet(me.getGson_showChat(),
				me.getRoleId());
	}

	// 更新玩家切磋设置
	public static void updateRoleFriendlyPk(MmochatPlayer me) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().updateRoleFriendlyPk(
				me.isAcceptFriendlyPk(), me.getRoleId());
	}

	// 更新玩家比武设置
	public static void updateRoleZhanjiPk(MmochatPlayer me) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().updateRoleZhanjiPk(me.isAcceptZhanjiPk(),
				me.getRoleId());
	}

	// 更新玩家其它设置
	public static void updateRoleOtherSetting(MmochatPlayer me) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().updateRoleOtherSetting(
				me.getGson_otherSystemSetting(), me.getRoleId());
	}

	// 更新角色死亡惩罚
	public static void updateRoleDead(MmochatPlayer me) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		if (me != null) {
			MmochatMain.getDaoService().updateRoleDead(me.getCurBlood(),
					me.getCurSprit(), me.getGson_pets(),
					me.getGson_myPackage(), me.getGson_propEffects(),
					me.getMapId(), me.getX(), me.getY(), me.getExp(),
					me.getDao(), (int) me.getSmall_money(),
					me.getGson_dailyActivities(), me.getRoleId());
		}
	}

	// 更新玩家领取VIP双倍
	public static void updateRoleGetVipDouble(MmochatPlayer me) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().updateRoleGetVipDouble(
				me.getLastGetVipDoublePropTime(), me.getGson_propEffects(),
				me.getRoleId());
	}

	// 创建帮派
	public static void createGang(MmochatPlayer me, String name,
			Map<Integer, MmochatGang> gangs) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		// 将创建人作为帮内成员
		Gson gson = new Gson();
		Map<Integer, MmochatGangMember> members = new ConcurrentHashMap<Integer, MmochatGangMember>();
		MmochatGangMember leader = new MmochatGangMember();
		leader.setRoleId(me.getRoleId());
		leader.setName(me.getName());
		leader.setBmpId(me.getBmpId());
		leader.setType(MmochatGangMemberType.帮主);
		members.put(leader.getRoleId(), leader);

		// 创建帮派并将创建人的帮派设为此帮派
		MmochatMain.getDaoService().createGang(
				gson.toJson(members,
						new TypeToken<Map<Integer, MmochatGangMember>>() {
						}.getType()), name, me, gangs, me.getGson_chenhao());

	}

	// 查找指定名字的帮派
	public static MmochatGang getGangByName(String name) throws Exception {
		if (!MmochatMain.serverType.isHasDao()) {
			return null;
		}
		try {
			return MmochatMain.getDaoService().getGangByName(name);
		} catch (EmptyResultDataAccessException e) {
			return null;
		} catch (Exception e) {
			throw e;
		}
	}

	// 加入帮派
	public static void enjorGang(MmochatPlayer me, int gang_id) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().enjorGang(gang_id, me.getRoleId());
	}

	// 查找指定ID的帮派
	public static MmochatGang getGangById(int id) throws Exception {
		if (!MmochatMain.serverType.isHasDao()) {
			return null;
		}
		try {
			return MmochatMain.getDaoService().getGangById(id);
		} catch (EmptyResultDataAccessException e) {
			return null;
		} catch (Exception e) {
			throw e;
		}
	}

	public static MmochatGang getGangByIdIncludeDeleted(int id)
			throws Exception {
		if (!MmochatMain.serverType.isHasDao()) {
			return null;
		}
		try {
			return MmochatMain.getDaoService().getGangByIdIncludeDeleted(id);
		} catch (EmptyResultDataAccessException e) {
			return null;
		} catch (Exception e) {
			throw e;
		}
	}

	// 设置帮派ID为-1
	public static void setNoGang(MmochatPlayer me) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().enjorGang(-1, me.getRoleId());
	}

	// 创建战队
	public static void createPkTeam(MmochatPlayer me, String name,
			Map<Integer, MmochatPkTeam> pkTeams) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		// 将创建人作为战队成员
		Gson gson = new Gson();
		Map<Integer, MmochatPkTeamMember> members = new ConcurrentHashMap<Integer, MmochatPkTeamMember>();
		MmochatPkTeamMember leader = new MmochatPkTeamMember();
		leader.setRoleId(me.getRoleId());
		leader.setName(me.getName());
		leader.setBmpId(me.getBmpId());
		leader.setType(MmochatPkTeamMemberType.队长);
		members.put(leader.getRoleId(), leader);

		// 创建战队并将创建人的战队设为此战队
		MmochatMain.getDaoService().createPkTeam(
				gson.toJson(members,
						new TypeToken<Map<Integer, MmochatPkTeamMember>>() {
						}.getType()), name, me, pkTeams);

	}

	// 查找指定ID的战队
	public static MmochatPkTeam getPkTeamById(int id) {
		if (!MmochatMain.serverType.isHasDao()) {
			return null;
		}
		return MmochatMain.getDaoService().getPkTeamById(id);
	}

	// 修改帮派公告
	public static void updateGangInfo(String newInfo, MmochatGang gang) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().updateGangInfo(newInfo, gang.getId());
		gang.setInfo(newInfo);
	}

	// 踢除帮派成员
	public static void kickOutGangMember(MmochatGang gang, int kickedRoleId,
			MmochatPlayer me) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		String members = gang.getGson_Members();
		String tasks = null, chenhao = null;
		if (me != null) {
			tasks = me.getGson_tasks();
			chenhao = me.getGson_chenhao();
		}
		MmochatMain.getDaoService().kickOutGangMember(members, gang.getId(),
				kickedRoleId, tasks, chenhao);
	}

	// 更新帮派成员
	public static void updateGangMember(MmochatGang gang) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		String members = gang.getGson_Members();
		MmochatMain.getDaoService().updateGangMember(members, gang.getId());
	}

	// 增加帮派成员
	public static void addGangMember(int roleId, MmochatGang gang) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		String members = gang.getGson_Members();
		MmochatMain.getDaoService()
				.addGangMember(roleId, members, gang.getId());
	}

	// 帮主解散帮派(只剩帮主一人时方可操作)
	public static void dismissGang(MmochatGang gang, MmochatPlayer master) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().deleteGangById(gang.getId(), master);
	}

	// 读取所有帮派
	public static List<MmochatGang> getAllGang() {
		if (!MmochatMain.serverType.isHasDao()) {
			return new ArrayList<MmochatGang>();
		}
		return MmochatMain.getDaoService().getAllGang();
	}

	// 完成帮派任务，更新帮派成员及帮派建设度，帮派资金
	public static void updateAfterGangTask(MmochatGang gang, int addBuildValue,
			int addmoney) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		String members = gang.getGson_Members();
		MmochatMain.getDaoService().updateAfterGangTask(members, addBuildValue,
				addmoney, gang.getId());
	}

	// 重置帮派成员每周帮贡
	public static void resetGangMemberWeekBuildValue(MmochatGang gang) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		String members = gang.getGson_Members();
		MmochatMain.getDaoService().resetGangMemberWeekBuildValue(members,
				gang.getLastDayClearMembersWeekBuildValue().getTime(),
				gang.getId());
	}

	// 研发帮派技能
	public static void developGangSkill(MmochatGang gang, int usedGangBuild) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		String skills = gang.getGson_Skills();
		MmochatMain.getDaoService().developGangSkill(usedGangBuild, skills,
				gang.getId());
	}

	// 成员学习帮派技能
	public static void learnGangSkill(MmochatGang gang, MmochatPlayer me) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		String gangMembers = gang.getGson_Members();
		String mySkills = me.getGson_gangSkills();
		MmochatMain.getDaoService().learnGangSkill(gangMembers, gang.getId(),
				mySkills, me.getRoleId());
	}

	// 更新帮派等级
	public static void updateGangLevel(MmochatGang gang) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().updateGangLevel(gang.getLevel().getValue(),
				gang.getId());
	}

	// 扣除帮派资金，加到帮主身上
	public static void delGangMoneyToManage(int delMoney, int gangId, int roleId) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().delGangMoneyToManage(delMoney, gangId,
				roleId);
	}

	// 更新角色游戏币
	public static void updateRoleSmallMoney(MmochatPlayer me) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().updateRoleSmallMoney(me.getRoleId(),
				(int) me.getSmall_money());
	}

	// 帮派大乱斗结束，更新帮派成员及帮派建设度，帮派资金
	public static void updateAfterGangPkGame(MmochatGang gangs) {
		List<MmochatGang> list = new ArrayList<MmochatGang>();
		list.add(gangs);
		batchUpdateAfterGangPkGame(list);
	}

	public static void batchUpdateAfterGangPkGame(List<MmochatGang> gangs) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		if (gangs == null || gangs.size() == 0) {
			return;
		}
		List<Object[]> args = new ArrayList<Object[]>();
		for (MmochatGang gang : gangs) {
			if (gang != null) {
				args.add(new Object[] { gang.getGson_Members(),
						gang.getBuildValue(), gang.getMoney(), gang.getId() });
			}
		}
		if (args.size() == 0) {
			return;
		}
		MmochatMain.getDaoService().batchUpdateAfterGangPkGame(args);
	}

	// 更新双方角色师徒信息
	public static void updateRoleTeacherAndStudent(MmochatPlayer teacher,
			MmochatPlayer student) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		int teacher_roleid = teacher.getTeacher_roleId();
		String teacher_name = teacher.getTeacher_name();
		String students = teacher.getGson_students();
		int roleId = teacher.getRoleId();

		int teacher_roleid2 = student.getTeacher_roleId();
		String teacher_name2 = student.getTeacher_name();
		String students2 = student.getGson_students();
		int roleId2 = student.getRoleId();
		MmochatMain.getDaoService().updateRoleTeacherAndStudent(teacher_roleid,
				teacher_name, students, roleId, teacher_roleid2, teacher_name2,
				students2, roleId2);
	}

	// 更新单方角色师徒信息
	public static void updateRoleTeacherAndStudent(MmochatPlayer me) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		int teacher_roleid = me.getTeacher_roleId();
		String teacher_name = me.getTeacher_name();
		String students = me.getGson_students();
		int roleId = me.getRoleId();

		MmochatMain.getDaoService().updateRoleTeacherAndStudent(teacher_roleid,
				teacher_name, students, roleId);
	}

	// 踢除徒弟
	public static void kickOutStudent(MmochatPlayer teacher, int studentRoleId) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		String students = teacher.getGson_students();
		MmochatMain.getDaoService().kickOutStudent(students, teacher,
				studentRoleId);
	}

	// 出师
	public static void gradute(MmochatPlayer me) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().gradute(me.getGson_myPackage(),
				me.getRoleId());
	}

	// 出师
	public static void gradute(MmochatPlayer me, MmochatPlayer teacher) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().gradute(teacher.getTeacher_roleId(),
				teacher.getTeacher_name(), teacher.getGson_students(),
				teacher.getRoleId(), me.getGson_myPackage(), me.getRoleId());
	}

	// 领取师傅工资
	public static void getTeacherSalary(MmochatPlayer me) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		String myPackage = me.getGson_myPackage();
		MmochatMain.getDaoService().getTeacherSalary(myPackage, me.getRoleId());
	}

	// 更新玩家战绩
	public static void updateRoleZhanji(MmochatPlayer me) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().updateRoleZhanji(me.getZhanji(),
				me.getRoleId());
	}

	// 更新同屏显示上限
	public static void updateScreenRoleNum(MmochatPlayer me) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().updateScreenRoleNum(
				me.getMax_screen_role_num(), me.getRoleId());
	}

	// 更新包裹
	public static void updateMyPackage(MmochatPlayer me) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		if (me != null) {
			MmochatMain.getDaoService().updateMyPackage(me.getGson_myPackage(),
					(int) me.getSmall_money(), me.getRoleId());
		}
	}

	// 批量更新包裹
	public static void batchUpdateMyPackage(List<MmochatPlayer> players) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		List<Object[]> args = new ArrayList<Object[]>();
		if (players == null || players.size() == 0) {
			return;
		}
		for (MmochatPlayer me : players) {
			if (me != null) {
				args.add(new Object[] { me.getGson_myPackage(),
						me.getSmall_money(), me.getRoleId() });
			}
		}
		if (args.size() == 0) {
			return;
		}
		MmochatMain.getDaoService().batchUpdateMyPackage(args);
	}

	// 更新包裹和仓库
	public static void updateMyPackageAndStorage(MmochatPlayer me) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		if (me != null) {
			MmochatMain.getDaoService().updateMyPackageAndStorage(
					me.getGson_myPackage(), me.getGson_myStorage(),
					me.getRoleId());
		}
	}

	// 更新仓库
	public static void updateMyStorage(MmochatPlayer me) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		if (me != null) {
			MmochatMain.getDaoService().updateMyStorage(me.getGson_myStorage(),
					me.getRoleId());
		}
	}

	// 通用数据库语句
	public static String commonSqlQuery(int tableKey, int actionType, String sql) {
		if (!MmochatMain.serverType.isHasDao()) {
			return null;
		}
		return MmochatMain.getDaoService().commonSqlQuery(tableKey, actionType,
				sql);
	}

	// 批量加金钱和元宝
	public static void batchUpdateMoney(List<Object[]> args) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().batchUpdateMoney(args);
	}

	// 更新日常活动和战绩
	public static void updateRoleDailyActivityAndZhanJi(MmochatPlayer me) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().updateRoleDailyActivityAndZhanJi(
				me.getZhanji(), me.getGson_dailyActivities(), me.getRoleId());
	}

	// 更新日常活动和包裹
	public static void updateRoleDailyActivityAndPackage(MmochatPlayer me) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().updateRoleDailyActivityAndPackage(
				me.getGson_myPackage(), me.getGson_dailyActivities(),
				me.getRoleId());
	}

	// 更新日常活动和包裹和宠物
	public static void updateRoleDailyActivityAndPackageAndPet(MmochatPlayer me) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().updateRoleDailyActivityAndPackageAndPet(
				me.getGson_myPackage(), me.getGson_dailyActivities(),
				me.getGson_pets(), me.getRoleId());
	}

	// 更新日常活动
	public static void updateRoleDailyActivity(MmochatPlayer me) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().updateRoleDailyActivity(
				me.getGson_dailyActivities(), me.getRoleId());
	}

	// 更新奖券及连续天数,最后领取时间
	public static void updateRoleLottery(MmochatPlayer me) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().updateRoleLottery(me.getLottery(),
				me.getSustainedLotteryDays(), me.getLastLotteryTime(),
				me.getDao(), me.getRoleId());
	}

	// 更新奖券和包裹
	public static void updateRoleLotteryAndPackage(MmochatPlayer me) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().updateRoleLotteryAndPackage(
				me.getLottery(), me.getGson_myPackage(), me.getRoleId());
	}

	// 批量更新玩家包裹和仓库
	public static void batchUpdatePackageAndStorage(List<Object[]> args) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().batchUpdatePackageAndStorage(args);
	}

	// 批量更新玩家道具效果
	public static void batchUpdateRolePropEffect(List<Object[]> args) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().batchUpdateRolePropEffect(args);
	}

	// 获取GM信息
	public static MmochatGm getGmByName(String name) throws Exception {
		if (!MmochatMain.serverType.isHasDao()) {
			return null;
		}
		try {
			return MmochatMain.getDaoService().getGmByName(name);
		} catch (EmptyResultDataAccessException e) {
			return null;
		} catch (Exception e) {
			throw e;
		}
	}

	// 获取未处理的玩家问题
	public static String getKefuQuestion() {
		if (!MmochatMain.serverType.isHasDao()) {
			return null;
		}
		return MmochatMain.getDaoService().getkefuQuestion();
	}

	// 更新未处理的玩家问题
	public static void saveKefuQuestion(String question) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().saveKefuQuestion(question);
	}

	// 新增一条空客服记录
	public static void addNewKefuQuestion() {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().addNewKefuQuestion();
	}

	// 增加道行
	public static void addRoleDao(int roleId, int add) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().addRoleDao(roleId, add);
	}

	// 增加经验
	public static void addRoleExp(int roleId, int add) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().addRoleExp(roleId, add);
	}

	// 增加战绩
	public static void addRoleZhanJi(int roleId, int add) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().addRoleZhanJi(roleId, add);
	}

	// 增加金钱
	public static void addRoleSmallMoney(int roleId, int add) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().addRoleSmallMoney(roleId, add);
	}

	// 增加元宝
	public static void addRoleBigMoney(int roleId, int add) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().addRoleBigMoney(roleId, add);
	}

	// 增加玩家奖券
	public static void addRoleLottery(int roleId, int addLottery) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().addRoleLottery(addLottery, roleId);
	}

	// 增加等级
	public static void addRoleLevelAndAttr(MmochatPlayer me) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().addRoleLevelAndAttr(me.getLevel(),
				me.getBlood_point(), me.getAttack_point(), me.getSprit_point(),
				me.getSpeed_point(), me.getSpace_point(),
				me.getSpace_gift_point(), me.getRoleId());
	}

	// 增加抽奖次数
	public static void addRoleAwardTimes(int roleId, int add) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().addRoleAwardTimes(roleId, add);
	}

	// 增加客服操作记录
	public static void addGmOptionLog(int kefu_id, int role_id,
			String role_name, int type, String content, String reason) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().addGmOptionLog(kefu_id, role_id, role_name,
				type, content, reason);
	}

	// 读取客服操作记录
	public static List<MmochatKefuOptionLog> getGmOptionLogById(int type,
			int start, int count) {
		if (!MmochatMain.serverType.isHasDao()) {
			return new ArrayList<MmochatKefuOptionLog>();
		}
		return MmochatMain.getDaoService().getGmOptionLogById(type, start,
				count);
	}

	// 获取name对应的roleId
	public static int getRoleIdByName(String name) {
		if (!MmochatMain.serverType.isHasDao()) {
			return -1;
		}
		return MmochatMain.getDaoService().getRoleIdByName(name);
	}

	// 创建新订单
	public static void createNewOrder(long order_id, int roleid, long skyid) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().createNewOrder(order_id, roleid, skyid,
				(new Date()).getTime());
	}

	// 设置订单成功
	public static boolean setOrderSuccess(String sky_chargeid, int rmb,
			String result_info, long order_id, int roleId, int addBigMoney,
			int addAwardTimes, int dao, int exp) {
		if (!MmochatMain.serverType.isHasDao()) {
			return false;
		}
		return MmochatMain.getDaoService().setOrderSuccess(sky_chargeid, rmb,
				result_info, order_id, roleId, addBigMoney, addAwardTimes,
				new Date().getTime(), dao, exp);
	}

	// 设置订单失败
	public static int setOrderFailed(String sky_chargeid, int rmb,
			String result_info, long order_id, int roleId) {
		if (!MmochatMain.serverType.isHasDao()) {
			return 0;
		}
		return MmochatMain.getDaoService().setOrderFailed(sky_chargeid, rmb,
				result_info, order_id, roleId);
	}

	// 创建kb兑换新订单
	public static void createNewKbOrder(int roleid, long skyid, int kb,
			int bigmoney, int addAwardTimes, int dao, int exp) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().createNewKbOrder(roleid, skyid, kb,
				bigmoney, addAwardTimes, new Date().getTime(), dao, exp);
	}

	// 预充值
	public static void delayPayOrder(int roleid, int bigmoney,
			int addAwardTimes, int dao, int exp) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().delayPayOrder(roleid, bigmoney,
				addAwardTimes, new Date().getTime(), dao, exp);
	}

	// 保存每日统计数据
	public static void saveDailyStatistics(long timeBefore7Day,
			Timestamp timeBefore6Day, int reg_num, int login_num,
			int loginNumOfYesterdayReg, int online_top,
			int online_time_average, int bigmoney_pay_role_num,
			int bigmoney_pay_total_money, String main_point_to_cost_smallmoney,
			String main_point_to_produce_smallmoney,
			String main_point_to_cost_bigmoney,
			String main_point_to_produce_bigmoney, String online_map,
			String direct_pay_role_money_map, String kb_pay_role_money_map,
			int suggest_reg_num, long today_score_to_bigmoney_count,
			long today_score_to_kb_count, int todayDirectPayTimes,
			int todayKBPayTimes, String today_propCostPointMap) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		long time = System.currentTimeMillis() - MmochatConstant.MS_PER_DAY * 7;
		List<MmochatRoleLevelInfoStatistics> levelStatistics = null;
		try {
			levelStatistics = MmochatMain.getDaoService()
					.getAllPlayerLevelInfo(time);
		} catch (Exception e) {
			e.printStackTrace();
		}
		String levelInfo = "";
		String activityLevelInfo = "";
		long now = System.currentTimeMillis();
		if (levelStatistics != null) {
			for (MmochatRoleLevelInfoStatistics info : levelStatistics) {
				levelInfo += info.getLevel() + ",";
				if (now - info.getLatest_offline_time() < MmochatConstant.MS_PER_DAY) {
					// 1天内登陆过的用户
					activityLevelInfo += info.getLevel() + ",";
				}
			}
		}

		MmochatMain.getDaoService().saveDailyStatistics(timeBefore7Day,
				timeBefore6Day, reg_num, login_num, loginNumOfYesterdayReg,
				online_top, online_time_average, bigmoney_pay_role_num,
				bigmoney_pay_total_money, main_point_to_cost_smallmoney,
				main_point_to_produce_smallmoney, main_point_to_cost_bigmoney,
				main_point_to_produce_bigmoney, online_map,
				direct_pay_role_money_map, kb_pay_role_money_map,
				suggest_reg_num, today_score_to_bigmoney_count,
				today_score_to_kb_count, levelInfo, activityLevelInfo,
				todayDirectPayTimes, todayKBPayTimes, today_propCostPointMap);
	}

	// 保存每月统计数据
	public static void saveMonthlyStatistics() {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		Calendar calendar = Calendar.getInstance();
		calendar.add(Calendar.MONTH, -1); // 得到前一个月
		long lastMonthTime = calendar.getTimeInMillis();
		calendar.add(Calendar.MONTH, -1); // 得到2个月前的时间
		Timestamp twoMonthBefore = new Timestamp(calendar.getTimeInMillis());
		MmochatMain.getDaoService().saveMonthlyStatistics(lastMonthTime,
				twoMonthBefore);
	}

	// 查询用户日报表数据
	public static List<MmochatDailyUserStatistics> queryDailyUserStatistics(
			Timestamp startDate, Timestamp endDate) {
		if (!MmochatMain.serverType.isHasDao()) {
			return new ArrayList<MmochatDailyUserStatistics>();
		}
		return MmochatMain.getDaoService().queryDailyUserStatistics(startDate,
				endDate);
	}

	// 查询消费日报表数据
	public static List<MmochatDailyMoneyStatistics> queryDailyMoneyStatistics(
			Timestamp startDate, Timestamp endDate) {
		if (!MmochatMain.serverType.isHasDao()) {
			return new ArrayList<MmochatDailyMoneyStatistics>();
		}
		return MmochatMain.getDaoService().queryDailyMoneyStatistics(startDate,
				endDate);
	}

	// 查询月报表数据
	public static List<MmochatMonthlyStatistics> queryMonthlyStatistics(
			Timestamp startDate, Timestamp endDate) {
		if (!MmochatMain.serverType.isHasDao()) {
			return new ArrayList<MmochatMonthlyStatistics>();
		}
		return MmochatMain.getDaoService().queryMonthlyStatistics(startDate,
				endDate);
	}

	// 查询指定玩家的交易记录
	public static List<MmochatDealLog> queryRoleDealLog(int roleId,
			Timestamp startDate, Timestamp endDate) {
		if (!MmochatMain.serverType.isHasDao()) {
			return new ArrayList<MmochatDealLog>();
		}
		return MmochatMain.getDaoService().queryRoleDealLog(roleId, startDate,
				endDate);
	}

	// 获取指定name的角色，包括已删除角色
	public static MmochatPlayer getRoleByName(String name) {
		if (!MmochatMain.serverType.isHasDao()) {
			return null;
		}
		return MmochatMain.getDaoService().getRoleByName(name);
	}

	// 更新积分和元宝
	public static void updateSuggestScoreAndBigmoney(int delSuggestScore,
			int addBigMoney, int roleId) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().updateSuggestScoreAndBigmoney(
				delSuggestScore, addBigMoney, roleId);
	}

	// 给推荐人增加积分
	public static int addSuggestScore(int addScore, int roleId) {
		if (!MmochatMain.serverType.isHasDao()) {
			return 0;
		}
		return MmochatMain.getDaoService().addSuggestScore(addScore, roleId);
	}

	// 更新包裹、宠物、游戏币、道行和抽奖次数
	public static void updateRoleAfterAward(MmochatPlayer me,
			int addSuggestScore) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		String myPackage = me.getGson_myPackage();
		String pets = me.getGson_pets();
		int rest_award_times = me.getRest_award_times();
		int smallMoney = (int) me.getSmall_money();
		int dao = me.getDao();
		int roleId = me.getRoleId();
		MmochatMain.getDaoService().updateRoleAfterAward(myPackage, pets,
				addSuggestScore, smallMoney, dao, rest_award_times, roleId);
	}

	// 更新宠物列表和宠物仓库
	public static void updateRolePetsAfterStore(MmochatPlayer me) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().updateRolePetsAfterStore(me.getGson_pets(),
				me.getGson_stored_pets(), me.getRoleId());
	}

	// 查询指定交易记录
	public static MmochatDealLog queryRoleDealLogById(int id) {
		if (!MmochatMain.serverType.isHasDao()) {
			return null;
		}
		try {
			return MmochatMain.getDaoService().queryRoleDealLogById(id);
		} catch (EmptyResultDataAccessException e) {
			return null;
		}
	}

	// 读取所有未结束的交易
	public static List<MmochatBigMoneyDeal> getAllUnclosedDeal() {
		if (!MmochatMain.serverType.isHasDao()) {
			return new ArrayList<MmochatBigMoneyDeal>();
		}
		return MmochatMain.getDaoService().getAllUnclosedDeal();
	}

	// 创建新订单
	public static void createBigMoneyDealOrder(MmochatBigMoneyDeal newOrder,
			int addSmallMoney, int addBigMoney) throws Exception {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().createBigMoneyDealOrder(newOrder,
				addSmallMoney, addBigMoney);
	}

	// 购买元宝订单
	public static void buyBigMoneyDeal(MmochatBigMoneyDeal order, int buyNum,
			int buyer_bigMoneyAdd, int buyer_smallMoneyAdd,
			int buyer_account_bigMoneyAdd, int buyer_account_smallMoneyAdd,
			long buyer_limit_bigMoney, int buyer_roleId,

			int seller_bigMoneyAdd, int seller_smallMoneyAdd,
			int seller_account_bigMoneyAdd, int seller_account_smallMoneyAdd,
			long seller_limit_bigMoney, int seller_roleId) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}

		MmochatMain.getDaoService().buyBigMoneyDeal(buyNum,
				order.getState().getKey(), order.getGson_dealerMap(),
				order.getId(),

				buyer_bigMoneyAdd, buyer_smallMoneyAdd,
				buyer_account_bigMoneyAdd, buyer_account_smallMoneyAdd,
				buyer_limit_bigMoney, buyer_roleId,

				seller_bigMoneyAdd, seller_smallMoneyAdd,
				seller_account_bigMoneyAdd, seller_account_smallMoneyAdd,
				seller_limit_bigMoney, seller_roleId);
	}

	// 批量设置元宝过期，并归还玩家金钱元宝
	public static void batchUpdateAfterBigMoneyDealTimeOut(
			List<MmochatBigMoneyDeal> deals) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		if (deals == null || deals.size() == 0) {
			return;
		}
		List<Object[]> orderArgs = new ArrayList<Object[]>();
		List<Object[]> playerArgs = new ArrayList<Object[]>();
		for (MmochatBigMoneyDeal deal : deals) {
			orderArgs
					.add(new Object[] { deal.getState().getKey(), deal.getId() });
			if (deal.getType() == MmochatBigMoneyDealType.寄售) {
				// 归还剩余元宝
				playerArgs.add(new Object[] { deal.getRest(), 0,
						deal.getRoleId() });
			} else if (deal.getType() == MmochatBigMoneyDealType.求购) {
				// 归还剩余金钱
				playerArgs.add(new Object[] { 0,
						deal.getRest() * deal.getPrice() * 100,
						deal.getRoleId() });
			}
		}
		MmochatMain.getDaoService().batchUpdateAfterBigMoneyDealTimeOut(
				orderArgs, playerArgs);
	}

	// 批量删除元宝交易订单
	public static void batchDeleteBigMoneyDeal(List<MmochatBigMoneyDeal> deals) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		if (deals == null || deals.size() == 0) {
			return;
		}
		List<Object[]> orderArgs = new ArrayList<Object[]>();
		for (MmochatBigMoneyDeal deal : deals) {
			orderArgs
					.add(new Object[] { deal.getState().getKey(), deal.getId() });
		}
		MmochatMain.getDaoService().batchDeleteBigMoneyDeal(orderArgs);
	}

	// 从交易账户取出元宝
	public static void getBigMoneyFromDealAccount(int getValue, int roleId) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService()
				.getBigMoneyFromDealAccount(getValue, roleId);
	}

	// 从交易账户取出金钱
	public static void getSmallMoneyFromDealAccount(int getValue, int roleId) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().getSmallMoneyFromDealAccount(getValue,
				roleId);
	}

	// 查询最近几个游戏币相关的记录
	public static List<MmochatSmallMoneyStatistics> queryLatestSmallMoneyStatistics(
			Timestamp startDate, Timestamp endDate) {
		if (!MmochatMain.serverType.isHasDao()) {
			return new ArrayList<MmochatSmallMoneyStatistics>();
		}
		return MmochatMain.getDaoService().queryLatestSmallMoneyStatistics(
				startDate, endDate);
	}

	// 查询最近几个元宝相关的记录
	public static List<MmochatBigMoneyStatistics> queryLatestBigMoneyStatistics(
			Timestamp startDate, Timestamp endDate) {
		if (!MmochatMain.serverType.isHasDao()) {
			return new ArrayList<MmochatBigMoneyStatistics>();
		}
		return MmochatMain.getDaoService().queryLatestBigMoneyStatistics(
				startDate, endDate);
	}

	// 创建GM
	public static void addGm(MmochatGm gm) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().addGm(gm);
	}

	// 获取所有GM
	public static List<MmochatGm> getAllGm() {
		if (!MmochatMain.serverType.isHasDao()) {
			return new ArrayList<MmochatGm>();
		}
		return MmochatMain.getDaoService().getAllGm();
	}

	// 删除GM
	public static void delGm(String username) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().delGm(username);
	}

	// 修改GM信息
	public static void editGm(String truename, int priority, String username) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().editGm(truename, priority, username);
	}

	// 修改GM密码
	public static void editGmPwd(String pwd, String username) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().editGmPwd(pwd, username);
	}

	// 查询在线分布
	public static Map<Long, Integer> queryOnlineMap(Timestamp startDate,
			Timestamp endDate) {
		if (!MmochatMain.serverType.isHasDao()) {
			return null;
		}
		String onlineMapString = MmochatMain.getDaoService().queryOnlineMap(
				startDate, endDate);
		if (onlineMapString == null) {
			return null;
		}
		Gson gson = new Gson();
		Map<Long, Integer> onlineMap = gson.fromJson(onlineMapString,
				new TypeToken<Map<Long, Integer>>() {
				}.getType());
		return onlineMap;
	}

	// 查询等级分布
	public static MmochatRoleLevelInfo queryLevelMap(Timestamp startDate,
			Timestamp endDate) {
		if (!MmochatMain.serverType.isHasDao()) {
			return null;
		}
		return MmochatMain.getDaoService().queryLevelMap(startDate, endDate);
	}

	// 结婚,role1出钱
	public static void marry(MmochatPlayer role1, MmochatPlayer role2,
			int delMoney) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().marry(role1, role2, delMoney);
	}

	// 离婚
	public static void unMarry(MmochatPlayer role1, MmochatPlayer role2) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().unMarry(role1, role2);
	}

	// 增加新的活动记录
	public static void addNewActivityRecord(long skyId, int roleId, int count,
			MmochatActivityRecordType type, String text) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().addNewActivityRecord(skyId, roleId, count,
				type.getKey(), text);
	}

	// 查询活动记录
	public static List<MmochatActivityRecord> getActivityRecord(int type) {
		if (!MmochatMain.serverType.isHasDao()) {
			return null;
		}
		return MmochatMain.getDaoService().getActivityRecord(type);
	}

	// 查询活动记录
	public static List<MmochatActivityRecord> getActivityRecord2(int type,
			Timestamp startDate, Timestamp endDate) {
		if (!MmochatMain.serverType.isHasDao()) {
			return null;
		}
		return MmochatMain.getDaoService().getActivityRecord2(type, startDate,
				endDate);
	}

	public static void addNewActivityRecord2(long skyId, int roleId, int count,
			int activityId, String text) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().addNewActivityRecord(skyId, roleId, count,
				activityId, text);
	}

	// 读取所有商店
	public static List<MmochatPlayerShop> getAllShops(int startId, int endId) {
		if (!MmochatMain.serverType.isHasDao()) {
			return new ArrayList<MmochatPlayerShop>();
		}
		return MmochatMain.getDaoService().getAllShops(startId, endId);
	}

	// 创建新商店
	public static void createNewShop(MmochatPlayerShop shop, int moneyCost,
			int roleId) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().createNewShop(shop, shop.getGson_grids(),
				moneyCost, roleId);
	}

	// 获取新的商店ID
	public static int createNewShopId() {
		if (!MmochatMain.serverType.isHasDao()) {
			return 0;
		}
		return MmochatMain.getDaoService().createNewShopId();
	}

	// 商店上架
	public static void addObjToShop(MmochatPlayer me, MmochatPlayerShop shop) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().addObjToShop(me.getGson_myPackage(),
				me.getRoleId(), shop.getGson_grids(), shop.getPageNum(),
				shop.getId());
	}

	// 宠物上架
	public static void addPetToShop(MmochatPlayer me, MmochatPlayerShop shop) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().addPetToShop(me.getGson_pets(),
				me.getRoleId(), shop.getGson_grids(), shop.getPageNum(),
				shop.getId());
	}

	// 物品下架
	public static void getObjFromShop(MmochatPlayer me, MmochatPlayerShop shop) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().getObjFromShop(me.getGson_pets(),
				me.getGson_myPackage(), me.getRoleId(), shop.getGson_grids(),
				shop.getPageNum(), shop.getId());
	}

	// 更新好友列表和元宝
	public static void updateMyFriendsAndDelBigMoney(MmochatPlayer me,
			int delBigMoney, MmochatPlayer he) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().updateMyFriendsAndDelBigMoney(
				me.getGson_friends(), delBigMoney, me.getLimit_bigmoney(),
				me.getRoleId(), he.getGson_friends(), he.getRoleId());
	}

	// 获取前N名充值排名
	public static List<MmochatRolePayInfo> getTopPayList(int topCount) {
		if (!MmochatMain.serverType.isHasDao()) {
			return new ArrayList<MmochatRolePayInfo>();
		}
		return MmochatMain.getDaoService().getTopPayList(topCount);
	}

	// 地图守护神
	public static void saveMapGuiderData(MmochatPlayer me, int addDao) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().saveMapGuiderData(addDao,
				me.getGson_pets(), me.getGson_dailyActivities(),
				me.getZhanji(), me.getRoleId());
	}

	// 增加商店金钱
	public static void addShopMoney(int roleId, int add, int id) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().addShopMoney(roleId, add, id);
	}

	// 修改商店状态
	public static void editShopState(int state, int id) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().editShopState(state, id);
	}

	// 修改商店公告
	public static void editShopIntro(String intro, int id) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().editShopIntro(intro, id);
	}

	// 增加商店柜台
	public static void addShopPage(int roleId, int costMoney,
			MmochatPlayerShop shop) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().addShopPage(roleId, costMoney,
				shop.getGson_grids(), shop.getPageNum(), shop.getId());
	}

	// 更新商店柜台数据
	public static void updateShopPage(MmochatPlayerShop shop) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().updateShopPage(shop.getGson_grids(),
				shop.getPageNum(), shop.getId());
	}

	// 出售商店/取消出售
	public static void sellShop(int state, int price, int id) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().sellShop(state, price, id);
	}

	// 购买二手商店
	public static void buyShop(int roleid, int state, String role_name,
			int shopId, int costMoney, int sellerRoleId) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().buyShop(roleid, state, role_name, shopId,
				costMoney, sellerRoleId);
	}

	// 购买商店物品
	public static void buyShopObj(MmochatPlayer me, MmochatPlayerShop shop,
			int payMoney, int shopEarnMoney, int winScore) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().buyShopObj(shop.getGson_grids(), payMoney,
				shopEarnMoney, shop.getGson_sellLog(), winScore, shop.getId(),
				me.getGson_myPackage(), me.getRoleId());
	}

	// 购买商店宠物
	public static void buyShopPet(MmochatPlayer me, MmochatPlayerShop shop,
			int payMoney, int shopEarnMoney, int winScore) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().buyShopPet(shop.getGson_grids(), payMoney,
				shopEarnMoney, shop.getGson_sellLog(), winScore, shop.getId(),
				me.getGson_pets(), me.getRoleId());
	}

	// 商店扣租金
	public static void updateShopDailyPay(int del, int state, int delScore,
			int id) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService()
				.updateShopDailyPay(del, state, delScore, id);
	}

	// 保存称号
	public static void saveChenhao(MmochatPlayer me) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().saveChenhao(me.getGson_chenhao(),
				me.getRoleId());
	}

	// 增加道行并更新称号
	public static void addRoleDaoAndUpdateChenhao(int roleId, int add,
			String chenhao) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().addRoleDaoAndUpdateChenhao(chenhao, add,
				roleId);
	}

	// 更新包裹、元宝、道行
	public static void updateRolePackage_BigMoney_Dao(MmochatPlayer me,
			int addDao, int addBigMoney) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().updateRolePackage_BigMoney_Dao(
				me.getGson_myPackage(), addDao, addBigMoney, me.getRoleId());
	}

	// 查询指定玩家的充值额
	public static int getKBPayById(int roleId) {
		if (!MmochatMain.serverType.isHasDao()) {
			return 0;
		}
		return MmochatMain.getDaoService().getKBPayById(roleId);
	}

	// 查询指定玩家在指定时间内的充值额
	public static int getKBPayByIdAndTime(int roleId, long startTime,
			long endTime) {
		if (!MmochatMain.serverType.isHasDao()) {
			return 0;
		}
		return MmochatMain.getDaoService().getKBPayByIdAndTime(roleId,
				startTime, endTime);
	}

	// 查询指定玩家的卡密充值额
	public static int getDirectPayById(int roleId) {
		if (!MmochatMain.serverType.isHasDao()) {
			return 0;
		}
		return MmochatMain.getDaoService().getDirectPayById(roleId);
	}

	// 查询指定玩家的指定时间的充值额
	public static int getDirectPayByIdAndTime(int roleId, long startTime,
			long endTime) {
		if (!MmochatMain.serverType.isHasDao()) {
			return 0;
		}
		return MmochatMain.getDaoService().getDirectPayByIdAndTime(roleId,
				startTime, endTime);
	}

	// 增加事件记录
	public static void addEventLog(int type, long time, String title,
			String content) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().addEventLog(type, time, title, content);
	}

	// 读取事件记录
	public static List<MmochatEventLog> getEventLog(int type, long startTime,
			long endTime) {
		if (!MmochatMain.serverType.isHasDao()) {
			return new ArrayList<MmochatEventLog>();
		}
		return MmochatMain.getDaoService()
				.getEventLog(type, startTime, endTime);
	}

	// 读取所有事件记录
	public static List<MmochatEventLog> getAllEventLog(long startTime) {
		if (!MmochatMain.serverType.isHasDao()) {
			return new ArrayList<MmochatEventLog>();
		}
		return MmochatMain.getDaoService().getAllEventLog(startTime);
	}

	// 转生
	public static void reborn(MmochatPlayer me) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().reborn(me);
	}

	// 仙魔转换
	public static void changSecondRoleType(MmochatSecondRoleType roleType,
			int costBigMoney, long limit_bigmoney, int roleId) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().changSecondRoleType(roleType, costBigMoney,
				limit_bigmoney, roleId);
	}

	// 封号到一定时间
	public static void forbiddenRole(long tick, int roleId) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().forbiddenRole(tick, roleId);
	}

	// 保存经验、道行
	public static void saveExpAndDao(MmochatPlayer me) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().saveExpAndDao(me.getExp(), me.getDao(),
				me.getRoleId());
	}

	// 保存包裹、道行、战绩、游戏币
	public static void savePackageDaoZhanJiSmallMoney(MmochatPlayer me,
			int addSmallMoney) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().savePackageDaoZhanJiSmallMoney(
				me.getGson_myPackage(), me.getDao(), me.getZhanji(),
				addSmallMoney, me.getRoleId());
	}

	// 保存声望
	public static void setHonor(long honor, int roleId) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().setHonor(honor, roleId);
	}

	// 保存声望和经验、道行
	public static void saveHonorExpDao(MmochatPlayer me) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().saveHonorExpDao(me.getHonor(), me.getExp(),
				me.getDao(), me.getRoleId());
	}

	// 保存声望和包裹
	public static void saveHonorAndPackage(MmochatPlayer me) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().saveHonorAndPackage(me.getHonor(),
				me.getGson_myPackage(), me.getRoleId());
	}

	// 保存声望和宠物
	public static void saveHonorAndPets(MmochatPlayer me) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().saveHonorAndPets(me.getHonor(),
				me.getGson_pets(), me.getRoleId());
	}

	// 保存声望和游戏币
	public static void saveHonorAndSmallMoney(MmochatPlayer me,
			int delSmallMoney) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().saveHonorAndSmallMoney(me.getHonor(),
				delSmallMoney, me.getRoleId());
	}

	// 创建钱庄密码
	public static void updateStorePwd(String pwd, int state,
			long release_store_pwd_time, int roleId) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().createStorePwd(pwd, state,
				release_store_pwd_time, roleId);
	}

	// 读取role表总记录数
	public static int getRoleNum() {
		if (!MmochatMain.serverType.isHasDao()) {
			return 0;
		}
		return MmochatMain.getDaoService().getRoleNum();
	}

	public static List<MergeStep2Model1> getMergeStep2Model1(int start, int end) {
		if (!MmochatMain.serverType.isHasDao()) {
			return null;
		}
		return MmochatMain.getDaoService().getMergeStep2Model1(start, end);
	}

	public static void updateMergeStep2Model1(List<MergeStep2Model1> players) {

		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		if (players == null || players.size() == 0) {
			return;
		}
		List<Object[]> args = new ArrayList<Object[]>();
		for (MergeStep2Model1 me : players) {
			if (me != null) {
				args
						.add(new Object[] { me.getGson_friends(),
								me.getGson_enermys(), me.getGson_students(),
								me.getId() });
			}
		}
		if (args.size() == 0) {
			return;
		}
		MmochatMain.getDaoService().updateMergeStep2Model1(args);
	}

	public static void updateExtraAndPackage(MmochatPlayer me) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		if (me == null) {
			return;
		}
		MmochatMain.getDaoService().updateExtraAndPackage(me.getExtra(),
				me.getGson_myPackage(), me.getRoleId());
	}

	// 读取gang表总记录数
	public static int getGangNum() {
		if (!MmochatMain.serverType.isHasDao()) {
			return 0;
		}
		return MmochatMain.getDaoService().getGangNum();
	}

	// 合服时读取所有帮派
	public static List<MmochatGang> getAllGangOfMergeServer() {
		if (!MmochatMain.serverType.isHasDao()) {
			return null;
		}
		return MmochatMain.getDaoService().getAllGangOfMergeServer();
	}

	// 更新合服帮派成员
	public static void updateGangMemberOfMergeServer(MmochatGang gang) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().updateGangMemberOfMergeServer(
				gang.getGson_Members(), gang.getId());
	}

	// public static List<TestModel> test(int s, int e) {
	// return MmochatMain.getDaoService().test(s, e);
	// }

	// 更新副本完成奖励
	public static void updateRoleAfterFuBen(MmochatPlayer me) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().updateRoleAfterFuBen(
				me.getGson_dailyActivities(), me.getGson_myPackage(),
				me.getExp(), me.getLevel(), me.getDao(), me.getFuBenId(),
				me.getGson_pets(), (int) me.getSmall_money(), me.getRoleId());
	}

	// 更新秘籍技能
	public static void updateRoleSpecialSkill(MmochatPlayer me) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().updateRoleSpecialSkill(
				me.getGson_specialSkills(), me.getRoleId());
	}

	// 训练技能熟练度
	public static void trainRoleSpecialSkill(MmochatPlayer me) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().trainRoleSpecialSkill(
				(int) me.getBig_money(), me.getGson_specialSkills(),
				me.getGson_dailyActivities(), me.getRoleId());
	}

	// 更新每日活动
	public static void updateGangFuBenInfo(MmochatGang gang) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().updateGangFuBenInfo(
				gang.getGson_dailyActivities(), gang.getId());
	}

	// 更新帮派建设度和帮派资金
	public static void updateGangBuildAndMoney(int addBuildValue, int money,
			int id) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().updateGangBuildAndMoney(addBuildValue,
				money, id);
	}

	// 使用道具后，变更门派
	public static void changeFamily(MmochatPlayer me) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().changeFamily(me.getGson_skills(),
				me.getFamily().getValue(), me.getRoleType().getValue(),
				me.getGson_myPackage(), me.getRoleId());
	}

	// 变更性别
	public static void changeSex(MmochatPlayer me) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().changeSex(me.getSexual(),
				me.getRoleType().getValue(), me.getBmpId(), me.getRoleId());
	}

	// 读取竞技点
	public static Integer getPkScore(int roleId) {
		if (!MmochatMain.serverType.isHasDao()) {
			return null;
		}
		return MmochatMain.getDaoService().getPkScore(roleId);
	}

	// 更新竞技点
	public static void updatePkScore(int score, int roleId) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().updatePkScore(score, roleId);
	}

	// 更新生活技能
	public static void updateLifeSkill(MmochatPlayer me) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().updateLifeSkill(me.getGson_lifeSkills(),
				me.getRoleId());
	}

	// 更新生活技能和宠物列表
	public static void updateLifeSkillAndPets(MmochatPlayer me) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		if (me != null) {
			MmochatMain.getDaoService().updateLifeSkillAndPets(
					me.getGson_pets(), me.getGson_lifeSkills(),
					me.getGson_dailyActivities(), me.getRoleId());
		}
	}

	// 保存心情
	public static void updateMood(MmochatPlayer me) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		if (me != null) {
			MmochatMain.getDaoService().updateMood(me.getMoodInfo(),
					me.getRoleId());
		}
	}

	// 更新包裹、元宝、道行、经验、战绩
	public static void updateRoleOnlineAward(MmochatPlayer me) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().updateRoleOnlineAward(
				me.getGson_myPackage(), me.getDao(), (int) me.getBig_money(),
				me.getExp(), me.getZhanji(), me.getRoleId());
	}

	// 按IMEI获取前N个用户
	public static List<MmochatRolePayInfo> getRoleByImei(String imei,
			int limitNum) {
		if (!MmochatMain.serverType.isHasDao()) {
			return null;
		}
		return MmochatMain.getDaoService().getRoleByImei(imei, limitNum);
	}

	// 更新玩家诚信信息
	public static void setChiefRecord(MmochatPlayer me) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().setChiefRecord(me.getMoodInfo(),
				me.getGson_otherSystemSetting(), me.getRoleId());
	}

	// 借出宠物找回,me:出借人，he:借者
	public static void getBorrowedPetBack(MmochatPlayer me, MmochatPlayer he) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().getBorrowedPetBack(he.getGson_pets(),
				he.getGson_stored_pets(), he.getRoleId(),
				me.getGson_stored_pets(), me.getRoleId());
	}

	// 借出物品找回,me:出借人，he:借者
	public static void getBorrowedObjBack(MmochatPlayer me, MmochatPlayer he) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		if (me != null) {
			MmochatMain.getDaoService().getBorrowedObjBack(
					me.getGson_myPackage(), (int) me.getSmall_money(),
					me.getRoleId(), he.getGson_myPackage(),
					he.getGson_myStorage(), he.getRoleId());
		}
	}

	// 更新SkyId
	public static void updateRoleSkyId(long newSkyId, int roleId) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().updateRoleSkyId(newSkyId, roleId);
	}

	// 读取交易记录最大值
	public static int getDelDealLogMaxId() {
		if (!MmochatMain.serverType.isHasDao()) {
			return 0;
		}
		return MmochatMain.getDaoService().getDelDealLogMaxId();
	}

	// 读取交易记录最小值:startDate之后
	public static int getDelDealLogMinId(Timestamp startDate) {
		if (!MmochatMain.serverType.isHasDao()) {
			return 0;
		}
		return MmochatMain.getDaoService().getDelDealLogMinId(startDate);
	}

	// 读取有借条的roleId1
	public static List<Integer> queryBorrowedRole1DealLog(int s, int e) {
		if (!MmochatMain.serverType.isHasDao()) {
			return null;
		}
		return MmochatMain.getDaoService().queryBorrowedRole1DealLog(s, e);
	}

	// 读取有借条的roleId2
	public static List<Integer> queryBorrowedRole2DealLog(int s, int e) {
		if (!MmochatMain.serverType.isHasDao()) {
			return null;
		}
		return MmochatMain.getDaoService().queryBorrowedRole2DealLog(s, e);
	}

	// 获取包裹、仓库、宠物，仓库宠物
	public static MergeStep1Model1 getMergeStep1Model1(int roleId) {
		if (!MmochatMain.serverType.isHasDao()) {
			return null;
		}
		return MmochatMain.getDaoService().getMergeStep1Model1(roleId);
	}

	// 更新包裹、仓库、宠物，仓库宠物
	public static void updateMergeStep1Model1(MergeStep1Model1 data, int roleId) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().updateMergeStep1Model1(
				data.getPackageStr(), data.getStorageStr(), data.getPets(),
				data.getStored_pets(), roleId);
	}

	// 获取包裹、仓库、仓库宠物
	public static MergeStep1Model4 getMergeStep1Model4(int roleId) {
		if (!MmochatMain.serverType.isHasDao()) {
			return null;
		}
		return MmochatMain.getDaoService().getMergeStep1Model4(roleId);
	}

	// 更新包裹、仓库、仓库宠物
	public static void updateMergeStep1Model4(MergeStep1Model4 data, int roleId) {
		if (!MmochatMain.serverType.isHasDao()) {
			return;
		}
		MmochatMain.getDaoService().updateMergeStep1Model4(
				data.getPackageStr(), data.getStorageStr(),
				data.getStored_pets(), roleId);
	}

}
